package com.kayt.cyberBar.cpublic.business.dao.impl;

import java.sql.SQLException;
import java.util.LinkedHashMap;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.dao.EntityDao;
import com.kayt.cyberBar.cpublic.business.dao.IPublicTaskTypeDao;
import com.kayt.cyberBar.cpublic.business.entity.po.CPublicTaskType;

@Repository("publicTaskTypeDao")
public class PublicTaskTypeDaoImpl implements IPublicTaskTypeDao {
	@Autowired
	private EntityDao entityDao;
	@Override
	public CPublicTaskType findById(String taskTypeCodeId) {
		if(StringUtils.isNotEmpty(taskTypeCodeId)){
			Long id = null;
			try{
				id = Long.parseLong(taskTypeCodeId);
			}catch (Exception e) {
				return null;
			}
			return entityDao.findById(id, CPublicTaskType.class);
		}else{
			return null;
		}
	}

	@Override
	public Integer delete(String taskTypeCodeId) {
		if(StringUtils.isNotEmpty(taskTypeCodeId)){
			Long id = null;
			try{
				id = Long.parseLong(taskTypeCodeId);
				CPublicTaskType CPublicTaskType = entityDao.findById(id, CPublicTaskType.class);
				if(CPublicTaskType != null){
					entityDao.delete(CPublicTaskType);
					return 0;
				}else{
					return -1;
				}
			}catch (Exception e) {
				return -1;
			}
		}else{
			return -1;
		}
	}

	@Override
	public void modify(CPublicTaskType entity) throws SQLException {
		entityDao.update(entity);
	}

	@Override
	public PageData<CPublicTaskType> findByPage(String hql, Object[] params, LinkedHashMap<String, String> orderMap) throws SQLException {
		PageData<CPublicTaskType> taskTypePageData = this.entityDao.getPagingData(CPublicTaskType.class, -1, -1, hql, params, orderMap);
		return taskTypePageData;
	}

	@Override
	public Long save(CPublicTaskType entity) throws SQLException {
		return this.entityDao.save(entity);
	}

	@Override
	public PageData<CPublicTaskType> getTaskTypeList(LinkedHashMap<String, String> orderMap) throws SQLException {
		PageData<CPublicTaskType> taskTypePageData = this.entityDao.getPagingData(CPublicTaskType.class, -1, -1, null, null, orderMap);
		return taskTypePageData;
	}
}
